package com.tct.worktimeboard.config;

/**
 * @author Huhailong
 * @Description
 * @Date 2021/2/22.
 */
public class DataSourceContextHolder {

    private static final ThreadLocal<String> contextHolder = new InheritableThreadLocal<>();

    /**
     * 设置数据源
     * @param db 数据源
     */
    public static void setContextHolder(String db){
        contextHolder.set(db);
    }

    /**
     * 获取当前数据源
     * @return current datasource
     */
    public static String getDataSource(){
        return contextHolder.get();
    }

    /**
     * 清除数据源
     */
    public static void clear(){
        contextHolder.remove();
    }
}
